package cn.edu.java.thread.原子类;

import java.util.concurrent.atomic.LongAccumulator;

public class LongAccumulatorDemo {
    public static void main(String[] args) {
        // 创建一个初始值为0的LongAccumulator
        LongAccumulator accumulator = new LongAccumulator((x, y) -> x + y, 0);

        // 累加操作
        accumulator.accumulate(10);
        accumulator.accumulate(20);
        accumulator.accumulate(30);

        // 获取当前值
        long currentValue = accumulator.get();
        System.out.println("当前值：" + currentValue);

        // 重置累加器
        accumulator.reset();

        // 获取重置后的当前值
        long resetValue = accumulator.get();
        System.out.println("重置后的当前值：" + resetValue);
    }
}
